-- percent_damage
-- create by shuzy
-- 道具：  百分比伤害

return {
    apply = function(source, target, classId, value)
        -- 固定伤害

        -- 传入攻击者信息
        local assailantInfo = {
            ["property_id"] = classId,
        };

        local hp     = target:queryAttrib("hp");
        local max_hp = target:queryAttrib("max_hp");
        local damage  = math.modf(max_hp * value / 1000);

        -- 道具伤害加成
        if PropertyM.query(classId, "target") ~= PROPERTY_SELF then
            local prop = PropM.combine(source, "property_damage", 1);
            damage = PropM.apply(prop, damage);
        else
            -- 如果是对自己使用，且扣除的血量大于当前血量，则扣除到1点
            if damage >= hp then
                damage = hp - 1;
            end
        end

        -- 修正伤害值
        damage = PropertyM.fixPropertyDamage(source, target, classId, damage);

        if ItemM.query(classId, "apply") == "damage_and_drop" then
            -- 会掉落道具
            CombatM.doDamage(source, target, damage, 0, true, { assailantInfo = assailantInfo, });
        else
            CombatM.doDamage(source, target, damage, 0, false, { assailantInfo = assailantInfo, });
        end

        -- 抛出使用道具攻击事件
        EventMgr.fire(event.PROPERTY_ATTACK, { ["classId"] = classId, ["target"] = target, ["source"] = source});
    end,
};